<?php

namespace App\Http\ViewComposers;

use App\Handlers\role;
use Illuminate\View\View;
use App\Services\Config\ChannelsService;
use Illuminate\Support\Facades\Auth;

class ChannelRadioComposer
{
    public function __construct()
    {

    }

    public function compose(View $view)
    {
        $reqChannelId = ($view->reqChannelId == null ? old('channel_id') : $view->reqChannelId);
        $channels = Auth::guard('admin')->user()->getChannels(['game_id' => session('game_id')], 'channel_id');

        //拼出 渠道table
        $channelHtml = '';
        foreach ($channels as $channelId => $channelName) {
            $checked = '';


            if (isset($reqChannelId) && $channelId == $reqChannelId) {
                $checked = 'checked="checked"';
            }

            $channelHtml .= <<<EOF
<div class="col-sm-1" style="min-width: 20rem">
    <label>&emsp;$channelName
            <input type="radio" class="pull-left" $checked name="channel_id" value="$channelId">
    </label>
</div>
EOF;
        }

        $view->with(compact('channelHtml'));
    }
}